home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Games / Battleship ƒ / Code folder / Battleship.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-06  |  4.4 KB  |  163 lines  |  [TEXT/KAHL]

  1. #include    <Values.h>
  2. #include    <stdlib.h>
  3. #include    <sound.h>
  4. #include    <Quickdraw.h>
  5.  
  6. #define kGridSize                    10
  7.  
  8. #define kBaseResID                    128
  9. #define kYouWindowID                kBaseResID
  10. #define kEnemyWindowID                kBaseResID + 1
  11. #define kTextWindowID                kBaseResID + 2
  12. #define kMoveToFront                (WindowPtr)-1L
  13.  
  14. #define kRandomUpperLimit            32768
  15. #define kRandomRange                kGridSize
  16.  
  17. #define kBombDropSnd                5000
  18. #define kExplosionSnd                5001
  19. #define kSplashSnd                    5002
  20.  
  21. #define wYou                        kBaseResID
  22. #define wComputer                    kBaseResID+1
  23. #define wText                        kBaseResID+2
  24.  
  25. #define kPixelSize                    20
  26. #define kNullDotID                    144
  27. #define kBWHitDotID                    143
  28. #define kHitDotID                    145
  29. #define kMissDotID                    146
  30. #define kMinSpacedShots                35
  31.  
  32. #define kHorizDestroyerID            200
  33. #define kVertDestroyerID            201
  34. #define kHorizCruiserID                202
  35. #define kVertCruiserID                203
  36. #define kHorizSubID                    204
  37. #define kVertSubID                    205
  38. #define kHorizBattleshipID            206
  39. #define kVertBattleshipID            207
  40. #define kHorizCarrierID                208
  41. #define kVertCarrierID                209
  42.  
  43. #define kCarrierMin                    2
  44. #define kCarrierMax                    2
  45. #define kBattleshipMin                1
  46. #define kBattleshipMax                2
  47. #define kCruiserMin                    1
  48. #define kCruiserMax                    1
  49. #define kSubMin                        1
  50. #define kSubMax                        1
  51. #define kDestroyerMin                0
  52. #define kDestroyerMax                1
  53.  
  54. #define kCarrierSize                5
  55. #define kBattleshipSize                4
  56. #define kCruiserSize                3
  57. #define kSubSize                    3
  58. #define kDestroyerSize                2
  59.  
  60. #define mApple                        kBaseResID
  61. #define iAbout                        1
  62.  
  63. #define mFile                        kBaseResID + 1
  64. #define iNew                        1
  65. #define iQuit                        2
  66.  
  67. #define  mOptions                    kBaseResID + 3
  68. #define iSound                        1
  69.  
  70. #define kAddCheckMark                TRUE
  71. #define kRemoveCheckMark            FALSE
  72.  
  73. #define iPlayAgainCheckBox            1
  74. #define iQuitCheckBox                2
  75.  
  76. #define kExtraPopupPixels            25
  77.     
  78. #define kSpaceBarKey                49
  79.  
  80. #define    kVersionNumberStr            "\pv1.1.0"
  81.  
  82. #define kCongratulationsStr            "\pCongratulations!"
  83. #define kYouWinStr                    "\pYou Win!"
  84. #define kSorryStr                    "\pSorry"
  85. #define kYouLoseStr                    "\pYou Lose."
  86.  
  87. /***********/
  88. /* Structs */
  89. /***********/
  90.  
  91. typedef enum {
  92.     right, left, up, down
  93. } Direction;
  94.  
  95. typedef enum {
  96.     carrier = 1, battleship, cruiser, sub, destroyer
  97. } ShipsEnum;
  98.  
  99. typedef enum {
  100.     noTry = 144, hit, miss
  101. } cond;
  102.  
  103. typedef struct {
  104.     char    shipType;
  105.     int        shipResID;
  106.     cond    hitOrMiss;
  107. } Grid;
  108.  
  109. /***********/
  110. /* Globals */
  111. /***********/
  112.  
  113. int            youCount = 0, enemyCount = 0, shotCount = 0;
  114. Boolean        gDone, gYouHasGone = FALSE, gHasPopupControl, gHasSound = FALSE, useColor;
  115. Rect        gClockRect;
  116. Grid        enemy [kGridSize] [kGridSize], you [kGridSize] [kGridSize];
  117. WindowPtr    enemyWindow, youWindow, textWindow;
  118.  
  119. /*************/
  120. /* Functions */
  121. /*************/
  122.  
  123. void    ToolBoxInit ( void );
  124. void    WindowInit ( void );
  125. void    MenuBarInit ( void );
  126. void    EventLoop ( void );
  127. void    DoEvent ( EventRecord *eventPtr );
  128. void    HandleMouseDown ( EventRecord *eventPtr );
  129. void    DoUpdate ( EventRecord *eventPtr );
  130. void    HandleMenuChoice ( long menuChoice );
  131. void    HandleAppleChoice ( short item );
  132. void    HandleFileChoice ( short item );
  133. void    NewGame ( void );
  134. void    DrawDots ( Grid theGrid[][kGridSize] );
  135. void    GridInit ( Grid aGrid[][kGridSize] );
  136. void    PlaceEnemyShips ( void );
  137. void    DrawShipPart ( int resID, Rect pictureRect );
  138. int        Randomize ( void );
  139. void    PlaceAnEnemyShip ( int shipSize, int min, int max, char c );
  140. Boolean    FitsHoriz ( Grid theGrid[][kGridSize], int x, int y, int shipSize );
  141. Boolean    FitsVert ( Grid theGrid[][kGridSize], int x, int y, int shipSize );
  142. void    CheckPoint ( Point mouseLocal );
  143. void    DrawOneDot ( int dotID, Rect *dotRect );
  144. void    PtToDotRect ( Point aPoint, Rect *aRect );
  145. void    PtToRect ( Point aPoint, Rect *aRect );
  146. void    EraseShipPart ( Rect pictureRect );
  147. void    PlaceAShip ( int theMin, int theMax, int theHorizID, char theLetter );
  148. void    PtToShipRect ( Point aPoint, Rect *aRect, Boolean horiz, int min, int max );
  149. Boolean    Inbounds ( Point *tempPoint, Boolean horiz, int min, int max );
  150. void    DrawHorizDots ( Point aPoint, Point tempPoint, Rect *theRect, int min, int max );
  151. void    DrawVertDots ( Point aPoint, Point tempPoint, Rect *theRect, int min, int max );
  152. void    SetShipToGrid ( Grid theGrid[][kGridSize], Point tempPoint, 
  153.                             Boolean horiz, int min, int max, char c );
  154. Boolean    ItFits ( Boolean horiz, Point thePoint, int theMin, int theMax );
  155. cond    PlaceTheShot ( Point thePoint );
  156. void    PickEnemyShot ( void );
  157. void    HandleOptionsChoice ( short item );
  158. void    HandleSound ( void );
  159. Boolean    IsColour( void );
  160. Boolean    IsBadRandom ( Point thePoint, Boolean canCheck );
  161.  
  162.  
  163.